package com.shamoa.springbootredis.demos.messageListener;

import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;

/**
 * @author zy
 * @version 1.0
 * @date 2024/3/24 14:55
 * @description redis消息接收者
 **/
@Component
public class RedisMessageListener implements MessageListener {

    /**
     * 每次消息到达后都会回调此方法
     *
     * @param message
     * @param pattern
     */
    @Override
    public void onMessage(Message message, byte[] pattern) {
        String channel = new String(message.getChannel());
        System.out.println("消息的频道为: " + channel);
        System.out.println("订阅收到消息: " + new String(message.getBody()));
    }


}
